// CSE 142 Winter 2008, Marty Stepp // // This program displays IMDB's Top 250 movies that match a search string. // This initial version of the program doesn't draw any graphics and doesn't // break itself apart into methods for structure very well. import java.awt.*; // for Graphics import java.io.*; // for File import java.util.*; // for Scanner public class Movies { public static void main(String[] args) throws FileNotFoundException { Scanner console = new Scanner(System.in); System.out.print("Search word? "); String searchWord = console.next(); // "Pulp" searchWord = searchWord.toLowerCase(); // look for that word in the file int matches = 0; Scanner input = new Scanner(new File("imdb.txt")); while (input.hasNextLine()) { // read a line, see if it matches, print it String line = input.nextLine(); String lineLC = line.toLowerCase(); // "5 8.8 247454 Pulp Fiction (1994)" // ^ int index = lineLC.indexOf(searchWord); if (index != -1) { // line matches matches++; Scanner lineScan = new Scanner(line); int rank = lineScan.nextInt(); // 5 double rating = lineScan.nextDouble(); // 8.8 int votes = lineScan.nextInt(); // 247454 String title = ""; while (lineScan.hasNext()) { // print title String token = lineScan.next(); title = title + " " + token; } System.out.println(rank + " " + votes + " " + rating + " " + title); } } System.out.println(matches + " matches."); } }